function Component() {

    this.__fields = Object.create(this.__defaults);
    this.init();
}


/**
 * 组件与对象的区别:
 * 
 * 1. 组件模板内可以使用slot
 * 2. 组件内部处于封装状态, 子对象直接冒泡到当前组件
 */
yaxi.Component = Node.extend(function (base) {



    // 扩展属性集支持
    extendProperties(Component);



    // 组件标记
    this.__component = 1;



    // 加载组件属性
    function loadProperties(component, properties) {

        for (var name in properties)
        {
            var value = properties[name];

            switch (name)
            {
                case 'bindings':
                    for (var key in value)
                    {
                        bindProperty(component, key, value[key]);
                    }
                    break;

                case 'events':
                    for (var key in value)
                    {
                        component.dom.addEventListener(key, value[key]);
                    }
                    break;

                case 'ref':
                    value(component);
                    break;

                case '__set_slots':
                    loadNamedSlots(component, value);
                    break;

                default:
                    component[name] = value;
                    break;
            }
        }
    }


    // 加载命名插槽
    function loadNamedSlots(component, values) {

        var slots, index, slot;

        if (slots = component.__slots)
        {
            index = 0;

            while (slot = slots[index++])
            {
                if (slot.name !== '$0')
                {
                    buildObjectChildren(slot, values && values[slot.name] || slot.__template);
                }
            }
        }
    }



    // 重载内部load
    this.__load = function (options) {

        var any;

        // 加载模板
        if (any = this.render())
        {
            this.renderNode(any[0], any[1]);

            if (any[2])
            {
                buildObjectChildren(this, any[2]);
            }
        }
        else
        {
            this.dom = document.createElement('div');
        }

        if (options && options[1])
        {
            loadProperties(this, options[1]);
        }

        // 加载默认插槽
        if ((any = this.__slots) && (any = any.$0))
        {
            if (options)
            {
                options = options[2];
            }

            if (options != null || (options = any.__template))
            {
                buildObjectChildren(any, options);
            }
        }

        // 加载子节点
        this.renderChildren();
    }


    // 渲染组件模板
    this.render = function () {
    }



}, Component);
